import { homePageData, shopConfig, sellerCenterData } from '../../service/api'

const state = {
    homedata : {},        //首页数据
    configureinfo : {},   //商城配置信息
    sellerminedata : {
        'applycount' : 0,   //申请分销商数量
        'fancount' : 0,     //粉丝数量
        'incomeprice' : '统计中',  //总收益
        'price' : '客官别急',        //余额
        'mydistributioncount' : 0,  //下级分销商数量
        'salecount' : 0,    //货架产品数量
        'todayprice' : '统计中',   //今日收益
        'estimateprice' : '统计中',  //预计收益
        'outprice' : '统计中',   //提现
    }
}

// getters
const getters = {
    homedata : state => state.homedata,
    configureinfo : state => state.configureinfo,
    sellerminedata : state => state.sellerminedata,
}

// actions
const actions = {

    //首页数据
    async getHomeData ({ commit, state}, para) {
        let res = await homePageData();
        if(res.errcode == 0){
            commit('setHomeData', res.data);
        }
    },

    //商城配置信息
    async getConfigureinfo ({ commit, state}, para) {
        let res = await shopConfig();
        if(res.errcode == 0){
            commit('setConfigureinfo', res.data);
            para.callback(res.data);
        }
    },

    //分销中心数据
    async getSellerMineData ({ commit, state}, para) {
        let res = await sellerCenterData();
        if(res.errcode == 0){
            commit('setSellerMineData', res.data);
        }
    },
}

// mutations
const mutations = {
    setHomeData (state, obj) {
        state.homedata = obj;
    },
    setConfigureinfo (state, obj) {
        state.configureinfo = obj;
    },
    setSellerMineData (state, obj) {
        state.sellerminedata = obj;
    },
} 

export default {
  state,
  getters,
  actions,
  mutations
}
